<?php

/***  DOCUMENTATION LAYER

Ceo Sample Unit Test

Last Update: Aug 2007
  
DESCRIPTION
  this file provides a template for other simple unit tests.
  
NOTES
  $test_root dynamically sets root in order to keep tests working after
  they are moved to the __REPOSITORY directory
    
______________________________________________________________________________*/

$_tx0 = microtime();
$test_root = ( strpos(dirname(__FILE__), 'repository') === false ) ? '' : '../';


// Test Name
$test_name = 'captcha test using hn_captcha';

// Include Files
require_once($test_root . '../php_ceo/framework.class.php');

// Configure Test
$debug = 1;

// Test HN_CAPTCHA Class

// load file
$hn_root = $_SERVER['DOCUMENT_ROOT']. '/hn_captcha/';
require_once($hn_root . 'captcha.class.php');

// special css
$css = <<<CSS
#captcha
{
 width:250px; margin:0; padding:8px; text-align:center;
 font:11px/16px Verdana, Geneva, Arial, Helvetica, sans-serif;
 color:#660000; background:#fff6f6;
 border:1px solid #ccc;
}
#captcha p { margin:8px 0; }
#captcha form { margin:0; padding:0; }
p.captcha_refresh { color:#cc3333; font-size: 11px; font-style: italic; font-weight: normal; }
input.captcha_submit { font-size:20px; }
input.captcha_refresh  { font-size:10px; }
p.captcha_invalid { color: #cc3333; font-weight: bold; text-align:left;	}
.captchapict { margin:0; padding:0; border:2px solid #cccccc; }
CSS;

// configure
print $hn_root;
$temp_dir = $hn_root . 'img_bin_captcha_tmp/';
$ttf_dir = $hn_root . 'TTF/';


$HN_CFG = array
(
  // arguments
  'debug'          => $debug,
  'tempfolder'     => $temp_dir,      // string: absolute path (with trailing slash!) to a writeable tempfolder which is also accessible via HTTP!
  'badguys_url'    => '/',            // string: URL            
  'chars'          => 6,              // integer: number of chars to use for ID
  'maxtry'         => 4,              // integer: [1-9]      
  'maxsize'        => 24,             // integer: maximal size of chars
  'minsize'        => 16,             // integer: minimal size of chars
  
  // hardset      
  'noise'                  => 1,                            // boolean: TRUE = noisy chars | FALSE = grid
  'maxrotation'            => 30,                           // integer: define the maximal angle for char-rotation, good results are between 0 and 30
  'websafecolors'          => FALSE,                        // boolean
  'refreshlink'            => TRUE,                         // boolean
  'lang'                   => 'en',                         // string:  ['en'|'de']
  'secretstring'           => 'ceoframeworkcaptcha',
  'secretposition'         => 11,                           // integer: [1-32]
  'prefix'                 => 'hn_captcha_',                // string: prefix for the captcha-images, is needed to identify the files in shared tempfolders
  'collect_garbage_after'  => 20,                           // integer: the garbage-collector run once after this number of script-calls
  'maxlifetime'            => 60                            // integer: only imagefiles which are older than this amount of seconds will be deleted     
);

// construct
$Captcha =& new CeoCaptcha($HN_CFG);

// customize css
$Captcha->css = $css;

// response tree
if ( $Captcha->result == 1 ) print "<h4 style='color:green;'>captcha succeeded -- give a prize</h4>";
elseif ( $Captcha->result == 2 )
{
  print "<h4 style='color:red;'>captcha failed -- try again</h4>";
  print $Captcha->display_form();
  
}
elseif ( $Captcha->result == 3 )
{
  print "<h4 style='color:red;'>too many fails -- lock out!</h4>";
  #if( !headers_sent() && !empty($Captcha->badguys_url)) header('location: '.$Captcha->badguys_url );
}
else
{
  print $Captcha->display_form();
}

$Captcha->dump();

// Footer
$_txn = microtime();
$stx = number_format(((substr($_txn,0,9)) + (substr($_txn,-10)) - (substr($_tx0,0,9)) - (substr($_tx0,-10))),4); 
echo "<h6>test '$test_name' complete in $stx s</h6>";
?>
